//
// Created by d on 6/20/16.
//

#ifndef DEEPDR_TOOLS_H
#define DEEPDR_TOOLS_H

#include "glog/logging.h"
#include "gtest/gtest.h"
#include "common.h"
#include "classifier.h"
#include "gflags/gflags.h"

struct asd {
    Mat bleed;
    Mat exclude;
};

/*///////////////////////////////////////////////////////////////////////////////
 *  Vessel extract related functions
 */
Mat vessel_seg(Mat img);

asd bleed_process(Mat input);

void myImShow(Mat img, const char *name = NULL);

void myImWrite(Mat, const char *, int index = -1);

void myImDel(const char *name);

bool myFileExist(const char *name);

bool myImExist(const char *name);

Mat myIm2Double(Mat in);

Mat myIm2Int(Mat in);

Mat myImRead(const char *name, int flags = cv::IMREAD_COLOR, int index = -1);

int mat2byte(const Mat &img, void *buf, int maxsize = -1);

int myPause(char exitKey = -1);

Mat leakage_preprocess(Mat input);

double NormInv(double probability);

double NormInv(double probability, double mean, double sigma);

class Statics {
    int TP, TN, FP, FN;
public:

    Statics() :
            TP(0), TN(0), FP(0), FN(0) { }

    void addTP(int delta = 1) {
        TP++;
    }

    void addFP(int delta = 1) {
        FP++;
    }

    void addTN(int delta = 1) {
        TN++;
    }

    void addFN(int delta = 1) {
        FN++;
    }

    float precision() {
        return float(TP) / float(TP + FP);
    }

    float recall() {
        return float(TP) / float(TP + FN);
    }

    float accuracy() {
        return float(TP + TN) / float(TP + TN + FP + FN);
    }

    float F1() {
        return 2 * precision() * recall() / (precision() + recall());
    }

    string toString() {
        string str;
        str += "Result \n";
        str += "precision  : " + boost::lexical_cast<string>(precision()) + "\n";
        str += "recall     : " + boost::lexical_cast<string>(recall()) + "\n";
        str += "accuracy   : " + boost::lexical_cast<string>(accuracy()) + "\n";
        str += "F1         : " + boost::lexical_cast<string>(F1()) + "\n";
        str += "TP         : " + boost::lexical_cast<string>(TP) + "\n";
        str += "TN         : " + boost::lexical_cast<string>(TN) + "\n";
        str += "FP         : " + boost::lexical_cast<string>(FP) + "\n";
        str += "FN         : " + boost::lexical_cast<string>(FN) + "\n";
        return str;
    }
};


#endif //DEEPDR_TOOLS_H
